package com.lieve.bpm.timer;

import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;

import java.util.concurrent.TimeUnit;

/**
 * High memory requirement
 * PER_TICK
 * @author sunyoboy
 * 2021/6/8
 */
public class HashedWheelTimerTest {
    public static void main(String[] args) {
        testWheelTimer2();
    }

    private static void testWheelTimer1() {
        HashedWheelTimer wheel = new HashedWheelTimer();
        System.out.println("test print " + System.currentTimeMillis());
        wheel.newTimeout(new TimerTask() {
            @Override
            public void run(Timeout timeout) throws Exception {
                System.out.println(timeout.isExpired());
                System.out.println(timeout.isCancelled());
                System.out.println("test print" + System.currentTimeMillis());
            }
        }, 5000, TimeUnit.MILLISECONDS);
        wheel.stop();
    }

    public static void testWheelTimer2() {
        HashedWheelTimer hashedWheelTimer = new HashedWheelTimer();
        hashedWheelTimer.newTimeout(new TimerTask() {
            @Override
            public void run(Timeout timeout) throws Exception {
                System.out.println("timer " + System.currentTimeMillis());
                timeout.timer().newTimeout(timeout.task(), 5, TimeUnit.SECONDS);
            }
        }, 5, TimeUnit.SECONDS);
    }
}
